﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2.Inventory.Dialogs
{
    public partial class FND_QA : Form
    {
        public FND_QA()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string SelectedDocumentNumber { get; set; }

        void BindGrid()
        {
            QAManager oManager = new QAManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            switch (cboSearch.SelectedIndex)
            {
                case 0:
                    dt = oManager.BrowseByDocNum(txtSearch.Text);
                    break;
                case 1:
                    dt = oManager.BrowseByReference(txtSearch.Text);
                    break;
                case 2:

                    break;
            }
            oManager.Close();


            gridControl1.DataSource = dt;
            gridControl1.Refresh();
        }

        private void FND_QA_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 0;
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            BindGrid();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            this.SelectedDocumentNumber = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["DocNumber"]).ToString();
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                BindGrid();
            }
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }
    }
}
